package guichatapplication;

import java.util.ArrayList;
import javax.swing.ImageIcon;

public class CustomListCell {
  private String identify;
  private ArrayList<String> lstIdentifies; // Use for group
  private ArrayList<MessageListCell> messages;
  private ImageIcon image;

  public CustomListCell( String identify){
    this.identify = identify;    
    this.lstIdentifies = null;
    image = new javax.swing.ImageIcon(getClass().getResource("/guichatapplication/Image/9.png"));
    this.messages=new ArrayList<>();
  }
  
  public CustomListCell( String identify, String[] detail){
    this.identify = identify;    
    
    this.lstIdentifies=new ArrayList<>();
    for(String str: detail){
        this.lstIdentifies.add(str);
    }
    
    image = new javax.swing.ImageIcon(getClass().getResource("/guichatapplication/Image/9.png"));
    this.messages=new ArrayList<>();
  }
  
  public boolean isGroup() {
      if (this.lstIdentifies == null) {
          return false;
      }
      return true;
  }

  public String getIdentify() {
    return identify;
  }
  
  public ArrayList<String> getIdentifies(){
      return this.lstIdentifies;
  }
 
  public ImageIcon getImage() {    
    return image;
  } 

  public String toString() {
    return identify;
  }
  
  public void setUnreadMessage(){
      image = new javax.swing.ImageIcon(getClass().getResource("/guichatapplication/Image/new-message.gif"));
  }
  
  public void setNormal(){
      image = new javax.swing.ImageIcon(getClass().getResource("/guichatapplication/Image/9.png"));
  } 
  
  // This message is from client
  public void addMessage(String message){
      this.messages.add(new MessageListCell(-1, message));
  }
  
  public void addIdentify(String identify){
      if(this.lstIdentifies==null)
          this.lstIdentifies=new ArrayList<>();
      this.lstIdentifies.add(identify);
  }
  
  public void removeIdentify(String identify){
      this.lstIdentifies.remove(identify);
  }
  
  public ArrayList<MessageListCell> getMessage(){
      return this.messages;
  }
  
  public void deleteMessage(){
      this.messages.clear();
  }
}